using System.Collections.Generic;
using UnityEngine;

public class PreSetColorController : MonoBehaviour
{
	public delegate void PalettePurchased(bool isRV);

	[SerializeField]
	private ColorButton m_ColorButtonPrefab;

	[HideInInspector]
	public List<Color> currentPalette = new List<Color>();

	public PaletteScriptable defaultPalette;

	private ColorButton[] m_ColorButtons;

	public event PalettePurchased OnPalettePurchased;

	private void Start()
	{
		SetPalette(defaultPalette.colors);
	}

	public void SetPalette(List<Color> colors)
	{
		currentPalette = colors;
		if (m_ColorButtons != null)
		{
			ColorButton[] colorButtons = m_ColorButtons;
			for (int i = 0; i < colorButtons.Length; i++)
			{
				Object.Destroy(colorButtons[i].gameObject);
			}
		}
		m_ColorButtons = new ColorButton[currentPalette.Count];
		for (int j = 0; j < currentPalette.Count; j++)
		{
			m_ColorButtons[j] = Object.Instantiate(m_ColorButtonPrefab, base.transform);
			m_ColorButtons[j].Init(currentPalette[j]);
		}
	}

	public void OnPalettePurchasedEvent(bool isRV)
	{
		this.OnPalettePurchased(isRV);
	}

	public void ResetPalette()
	{
		SetPalette(defaultPalette.colors);
	}
}
